package interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import controller.InterceptorAction;
import lombok.Data;

import java.util.Date;

/**
 * 继承AbstractInterceptor类重写interceptor方法
 */
@Data
public class MyInterceptor extends AbstractInterceptor {
    private int sleep;
    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        System.out.println("开始执行:Interceptor"+new Date().toLocaleString());
        InterceptorAction interceptorAction= (InterceptorAction) invocation.getAction();//获得与拦截器连接的Action
        interceptorAction.setSleep(sleep);//设置Action的属性
        String result=invocation.invoke();//放行
        System.out.println("执行完毕:Action"+new Date().toLocaleString());
        return result;//result对应Action类中的返回值
    }
}
